<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>

<h1>欢迎来到登录页面</h1>

<div>
    用户名：<input type="text" id="ipt-username" name="username"><br/>
    密码：<input type="password" id="ipt-pwd" name="password"><br/>
    <button id="btn-login">登录</button>
    <button>重置</button>
</div>



</body>
</html>

<!--   ./  ../   -->
<script src="./js/axios.min.js">
</script>

<script>
// 获取元素 对象 绑定事件
    const loginBtObj = document.getElementById("btn-login");
    loginBtObj.onclick = function () {
        // alert(111)
        //点击后获取  input框中输入的值
        const userName = document.getElementById("ipt-username").value;
        const pwd = document.getElementById("ipt-pwd").value;
        // 发送 axios 请求
        // axios.post(url,data)
        const url = "/user/login";
        const data = {
            "username":userName,
            "password":pwd
        }
        axios
            .post(url,data)
            .then( function (res) {
                console.log(res.data)
                console.log(res)
                if(res.data.code === 200){
                    alert("登录成功")
                    window.location.href = "/static/index.html?username="+userName
                }else{
                    alert(res.data.msg)
                }

            });


    }


</script>
